function [slope,zeropoint] = swpSlopeFitting(swprResult, varargin)
    p=inputParser;
    p.addParameter('isPlot', true, @islogical)
    p.parse(varargin{:});
    
    swprData = swprResult.data;
    node = swprResult.node;
    data = swprData.getNodeData(node, 'x');
    [xData, yData] = prepareCurveData( data.grid, data.value );

    ft = fittype( 'poly1' );
    opts = fitoptions( 'Method', 'LinearLeastSquares' );

    % Fit model to data.
    [fitresult, ~] = fit( xData, yData, ft, opts );
    slope = fitresult.p1;
    zeropoint = -fitresult.p2./fitresult.p1;

    % Plot fit with data.
    if p.Results.isPlot
        figure( 'Name', 'Sweep Bias', 'WindowStyle', 'Docked');
        h = plot( fitresult, xData, yData );
        legend( h, 'demodSignal vs. bias', 'poly1 fit', 'Location', 'NorthEast' );
        xlim(minmax(data.grid'));
        % Label axes
        xlabel ('bias Volt(V)');
        ylabel ('demod signal(V)');
        grid on
        title(sprintf('V_0=%4.3f V',zeropoint))
    end
end
